﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TestContainer
{
    public partial class Form1 : Form
    {
        WebShooter.Snapshot s;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            comboBoxFileFormat.SelectedIndex = 0;
        }

        private void buttonGO_Click(object sender, EventArgs e)
        {
            s = new WebShooter.Snapshot();
            s.OnSnapshotReady += new WebShooter.Snapshot.OnSnapshotReadyHandler(s_OnSnapshotReady);
            s.URL = textBoxURL.Text;
            s.SnapshotSize = new Size(int.Parse(textBoxImageWidth.Text), int.Parse(textBoxImageHeight.Text));
            s.WebSiteSize  = new Size(int.Parse(textBoxBrowserWidth.Text), int.Parse(textBoxBrowserHeight.Text));
            s.Make();
        }

        void s_OnSnapshotReady(Bitmap b)
        {
            pictureBoxPreview.Image = b;

            if (checkBoxSave.Checked)
            {
                switch (comboBoxFileFormat.Text)
                {
                    case "BMP": s.SnapshotFormat = WebShooter.Snapshot.ImageFormat.bmp; break;
                    case "GIF": s.SnapshotFormat = WebShooter.Snapshot.ImageFormat.gif; break;
                    case "JPEG": s.SnapshotFormat = WebShooter.Snapshot.ImageFormat.jpeg; break;
                    case "PNG": s.SnapshotFormat = WebShooter.Snapshot.ImageFormat.png; break;
                }
                s.Save(textBoxFileName.Text);
            }

            MessageBox.Show("Done");
        }

        private void buttonFile_Click(object sender, EventArgs e)
        {
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBoxFileName.Text = saveFileDialog1.FileName;
            }
        }

       
    }
}
